<?php
    include_once("../action/checkAuthenticationAction.php");
    include_once("../service/commentService.php");
    include_once("../service/specialProductService.php");
    include_once("../util/constant.php");
    include_once("../service/userService.php");
    include_once("../service/categoryService.php");
    
    include_once("../util/authUtil.php");
    $perm_array = $_SESSION["permissions"];
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<title>Dashboard</title>
	<?php include("import-css.php");?>	
</head>
<body>
	<?php include("header.php");?>
    
    <div class="container-fluid">
		<div class="row-fluid">
            <!--Menu-->
            <?php include("menu.php");?>
            <!--Content-->
            <div class="box span10 offset2">
                <?php
                    $pro_id = isset($_GET["p"])?$_GET["p"]:0;
                    $rootComments = getBidsOfSpecialProduct($pro_id,1,null);
                ?>
    					<div class="box-header well" data-original-title>
                            <select onchange="loadcomments($(this).val());">
                                <option value="0">Chọn sản phẩm</option>
                                <?php
                                    $products = findAllSpecialProducts();
                                    while($product = mysql_fetch_array($products)){
                                ?>
                                        <option <?php echo $pro_id==$product["SPRO_ID"]?"selected":""; ?> value="<?php echo $product["SPRO_ID"]; ?>"><?php echo $product["PRO_NAME"] ?></option>
                                <?php
                                    }
                                ?>
                            </select>
    					</div>
    					<div class="box-content">
                           
                            <table class="table table-striped table-bordered bootstrap-datatable datatable">
                            <?php
                            if(!authUtil(array("edit comment","view comment"),$perm_array,false)){
                                echo "<script>window.location.href='../admin/index.php';</script>";
                            }
                            ?>
                                      <thead>
                                          <tr>
                                              <th>Người dùng</th>
                                              <th>Đấu giá</th>
                                              <th>Ngày</th>                  
                                          </tr>
                                      </thead>   
                                      <tbody>
                                            <?php
                                                while($rootComment = mysql_fetch_array($rootComments)){
                                            ?>
                                            <tr>
                                                <td>
                                                    <?php
                                                        $user = findUserById($rootComment["USER_ID"]);
                                                        $userInfo = mysql_fetch_array($user);
                                                        echo $userInfo["USER_USERNAME"];
                                                    ?>
                                                </td>
                                                <td>
                                                    <?php
                                                        echo $rootComment["COM_CONTENT"];
                                                    ?>
                                                </td>
                                                <td>
                                                    <?php
                                                        echo $rootComment["COM_CREATIONDATE"];
                                                    ?>
                                                </td>
                                            </tr>
                                            <?php                                        
                                                }
                                            ?>									
                                      </tbody>
                                  </table>  
                            </div>
            </div><!--/span-->
        </div>
    </div>

    <?php include("footer.php");?>
		
	</div><!--/.fluid-container-->

	<?php include("import-js.php");?>	
    <script>
    <?php
        $require_perm = array("edit comment");
        if(!authUtil($require_perm,$perm_array,false)){
            echo "$(':checkbox').attr('disabled', true);";      
        }
    ?>
    function loadcomments(pro_id){
        window.location.href="./bid.php?p="+pro_id;
    }
    </script>
</body>
</html>
